import requests
from openpyxl import Workbook
from bs4 import  BeautifulSoup
from pyecharts.charts import Line
from pyecharts.charts import Bar
from pyecharts.charts import Pie
nos=[]
title=[]
host=[]
name=[]
url="http://w3ic.com/"
#header={"User-Agent":" Mozilla/5.0"}
re = requests.get ( url)
#print(re.text)
soup=BeautifulSoup(re.text,"html.parser")
for li in soup.findAll(name="li",attrs={"class":"bang_1"}):
    nos.append(li.contents[1].string[0:3])
    host.append(li.contents[3].string[0:3])
    name.append(li.contents[5].string[0:3])
wb = Workbook()
ws = wb.active
rows=[]
ws.append(["排名","名称"])
ws['A1'] = "排名"
ws['B1'] = "名称"
for r in range(len(nos)):
     ws.append([nos[r],host[r],name[r]])
wb.save("电视剧排行榜.xlsx")
print(name)
print(nos)
print(host)
# from openpyxl import load_workbook
# wb = load_workbook("电视剧排行榜.xlsx")
# ws1 = wb.active
# #rows=[]
# for row in ws1.iter_rows():
#         for cell in row:
#                 print(cell.value,end=",")
#         print()
# bar=Bar()
# bar.add_xaxis(name)
# bar.add_yaxis("排名",nos)
# bar.add_yaxis("热点",host)
# bar.render("movie1.html")
# line=Line()
# line.add_xaxis(name)
# line.add_yaxis("排名",nos)
# line.add_yaxis("热点",host)
# line.render("movie1-折线.html")
# pie=Pie()
# pie.add(series_name="排行榜",data_pair=,radius=["30%","70%"],rosetype="radius")
# pie.set_series_opts(label_opts=options.LabelOpts(formatter="{b}:{d}%"))
# pie.set_series_opts(label_opts=options.LabelOpts(formatter="{b}的占比:百分比{d}%"))
# pie.render("饼图.html")
